import AbstractField from '@/components/hhd/design/FormDesigner/field/comps/AbstractField';
import {createDefaultFieldElement} from '@/utils/FormDesignUtils';
import {createField} from '@/components/hhd/design/FormDesigner/types';
import {guid} from '@/utils';
import $ from 'jquery';

export default class Date extends AbstractField {
    getFieldComponentTitle() {
        return '日期';
    }

    getFieldComponentName() {
        return 'date';
    }

    getDefaultConfig() {
        return new Promise((resolve) => {
            let field = createField();
            field.id = guid();
            field.component = 'date'
            field.fieldName = '日期'
            field.label = '日期'
            field.format = 'YYYY-MM-DD'
            field.placeholder = '请选择日期'
            resolve(field);
        });
    }

    createFieldElement() {
        return new Promise((resolve) => {
            resolve(this.createDefaultFieldElement());
        })
    }

    setFieldTitle(el, fieldConfig) {
        $(el).find('span[data-role=field-title]').html(fieldConfig.label);
    }

    createDefaultFieldElement() {
        let res = createDefaultFieldElement();
        res.innerHTML = '<div><span style="position: relative" data-role="field-title">日期</span><i aria-label="图标: calendar" class="anticon anticon-calendar ant-calendar-picker-icon"><svg viewBox="64 64 896 896" data-icon="calendar" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zm-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z"></path></svg></i></div>'
        return res;
    }
};
